﻿using B.S.Database.Domain.Entity;
using B.S.Database.ErrorCode;
using B.S.Database.Interface.Interface;
using B.S.Database.Read.Api.Application.Commands.Processing;
using MediatR;

namespace B.S.Database.Read.Api.Application.CommandHandler.Processing
{
    public class SupplierShowCommandHandler : IRequestHandler<SupplierShowCommands, Apiresult<List<Supplier>>>
    {
        private readonly IBaseResotity<Supplier> supplierRepo;

        public SupplierShowCommandHandler(IBaseResotity<Supplier> SupplierRepo)
        {
            supplierRepo = SupplierRepo;
        }
        public Task<Apiresult<List<Supplier>>> Handle(SupplierShowCommands request, CancellationToken cancellationToken)
        {
            Apiresult<List<Supplier>> res = new Apiresult<List<Supplier>>();
            res.Code = ApiEnums.成功;
            res.Message = ApiEnums.成功.ToString();
            var list = supplierRepo.GetAll().Where(c => c.TraceabilityId == request.TraceabilityId);
            res.Data = list.ToList();
            return Task.FromResult(res);
        }
    }
}
